﻿package UIComponents// ActionScript file
{
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ButtonScale extends Sprite
	{
		private var _enabled:Boolean=true;/*可否按*/
		private var _skin:DisplayObject;/*按钮皮肤*/
		public function ButtonScale():void
		{
			this.init();
		}
		
		private function init():void
		{
			if(this.numChildren)this._skin=this.getChildAt(0);
			this.addListener();
		}
		
		private function addListener():void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,upHandler);
			this.addEventListener(MouseEvent.ROLL_OVER,overHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,outHandler);
		}
		
		private function downHandler(e:MouseEvent):void
		{
			this.scaleIn();
		}
		
		private function upHandler(e:MouseEvent):void
		{
			this.scaleOut();
		}
		
		private function overHandler(e:MouseEvent):void
		{
			this.scaleOut();
		}
		
		private function outHandler(e:MouseEvent):void
		{
			this.scaleIn();
		}
		
		private function scaleOut():void
		{
			TweenLite.to(this.skin,0.2,{scaleX:1.2,scaleY:1.2});
		}
		
		private function scaleIn():void
		{
			TweenLite.to(this.skin,0.2,{scaleX:1,scaleY:1});
		}

		/*getter & setter*/
		public function get enabled():Boolean
		{
			return _enabled;
		}

		public function set enabled(value:Boolean):void
		{
			_enabled = value;
		}

		public function get skin():DisplayObject
		{
			return _skin;
		}


	}
}